﻿using System.Text.RegularExpressions;
using System.Windows.Forms;
using Me.Amon.Util;

namespace Me.Amon.POS.V
{
    public partial class WfPro : Form
    {
        public WfPro()
        {
            InitializeComponent();
        }

        public int PayAmount { get; set; }

        private void WfPro_Load(object sender, System.EventArgs e)
        {
            TbPay.SelectAll();
        }

        private void WfPay_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                e.Handled = true;
                Close();
                return;
            }

            if (e.KeyCode != Keys.Enter)
            {
                return;
            }

            var text = TbPay.Text.Trim();
            if (string.IsNullOrWhiteSpace(text))
            {
                LlPay.Text = "请输入折扣后的金额：";
                return;
            }
            if (!Regex.IsMatch(text, "^\\d+([.]\\d{1,2})?$"))
            {
                LlPay.Text = "请输入有效的折扣金额：";
                return;
            }

            PayAmount = CharUtil.ParsePrice(text);

            e.Handled = true;
            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
    }
}
